using UnityEngine;
using System.Collections.Generic;

public class Firewall : MonoBehaviour {
	
	List<Health> mbs;
	
	public float burnDamage = 10f;

	void Start() {
		//GetComponent<SelfDestructs>().lifeSpan *= GameManager.Instance.firewallEffectiveness;
	}
	
	void OnTriggerEnter2D(Collider2D col) {
		Debug.Log ("OnTriggerEnter2D");
		if(mbs == null)
			mbs = new List<Health>();
		
		Health mb = col.GetComponent<Health>();
		if(mb != null) {
			mb.TakeDamage(burnDamage * GameManager.Instance.firewallEffectiveness, true);
			mbs.Add(mb);
		}
	}
	
	void OnTriggerExit2D(Collider2D col) {
		if(mbs == null)
			mbs = new List<Health>();
		
		Health mb = col.GetComponent<Health>();
		if(mb != null) {
			mbs.Remove(mb);
		}
	}

	void Update() {
		if(mbs == null)
			return;

		foreach(Health mb in mbs) {
			if(mb != null) {
				mb.TakeDamage(burnDamage * GameManager.Instance.firewallEffectiveness, true);
			}
		}
	}

}
